$(document).ready(function (){
    var product_url = '/index/web/news'
    var download_url = '/index/web/download'
    var download_file_url = '/index/web/downloadFile'
    var question_url = '/index/web/question'

    //新闻页面加载更多
    var news_page_index = 0;
    $(".load-more-news").on('click',function (){
        news_page_index ++;
        $.ajax({
            type: 'POST',
            url: product_url,
            data: {"cat_id":8,"page_index":news_page_index,"page_size":3},
            success: function(res){
                if(res.code == 0){
                    if(res.data.list.length == 0){
                        alert('已经没有数据了')
                    }else{
                        $.each(res.data.list,function (k,v){
                            var html = '<a href="/index/web/news-detail/'+v.article_id+'" class="n-li">\n' +
                                '        <div class="toppic">\n' +
                                '          <img src="'+v.photo+'" alt="">\n' +
                                '        </div>\n' +
                                '        <div class="infobox">\n' +
                                '          <h5 class="tit dot2">'+v.title+'</h5>\n' +
                                '          <p class="txt">'+v.title_style+'</p>\n' +
                                '          <div class="time">\n' +
                                '            <img src="/static/images/clock.png" alt=""><span>'+v.create_time+'</span>\n' +
                                '          </div>\n' +
                                '        </div>\n' +
                                '      </a>';
                            $(".news-list").append(html);
                        })
                    }
                }else{
                    alert(res.msg)
                }
            },
            timeout: 2000,
            error: function(jqXHR,textStatus){
                console.log("请求失败，请稍后重试!");
            }
        })
    })

    $(".news-cate-tag").on("click",function (){
       news_page_index = 0
       $(this).addClass("on").siblings().removeClass("on");
       var cat_id = $(this).data("id");
        $.ajax({
            type: 'POST',
            url: product_url,
            data: {"cat_id":cat_id,"page_index":1,"page_size":3},
            success: function(res){
                if(res.code == 0){
                    if(res.data.list.length == 0){
                        alert('已经没有数据了')
                    }else{
                        $(".news-list").html("");
                        $.each(res.data.list,function (k,v){
                            var html = '<a href="/index/web/news-detail/'+v.article_id+'" class="n-li">\n' +
                                '        <div class="toppic">\n' +
                                '          <img src="'+v.photo+'" alt="">\n' +
                                '        </div>\n' +
                                '        <div class="infobox">\n' +
                                '          <h5 class="tit dot2">'+v.title+'</h5>\n' +
                                '          <p class="txt">'+v.title_style+'</p>\n' +
                                '          <div class="time">\n' +
                                '            <img src="/static/images/clock.png" alt=""><span>'+v.create_time+'</span>\n' +
                                '          </div>\n' +
                                '        </div>\n' +
                                '      </a>';
                            $(".news-list").append(html);
                            news_page_index = 1
                        })
                    }
                }else{
                    alert(res.msg)
                }
            },
            timeout: 2000,
            error: function(jqXHR,textStatus){
                console.log("请求失败，请稍后重试!");
            }
        })
    })

    $(".download-file").on("click",function (){
        var filename = $(this).data("url")
        url = download_file_url + '?filename=' + filename
        window.location.href = url
    })

    var download_page_index = 2
    $(".load-more-download").on("click",function (){
        $.ajax({
            type: 'POST',
            url: download_url,
            data: {"page_index":download_page_index,"page_size":2},
            success: function(res){
                if(res.code == 0){
                    if(res.data.list.length == 0){
                        alert('已经没有数据了')
                    }else{
                        $.each(res.data.list,function (k,v){
                            var html = '<div class="item wow fadeInUp" data-wow-delay=".1s">\n' +
                                '                    <div class="le-icon"><img src="/static/images/down1.png" alt=""></div>\n' +
                                '                    <div class="right">\n' +
                                '                        <div class="h3">'+v.title+'</div>\n' +
                                '                        <div class="box">\n' +
                                '                            <a class="lay"> \n' +
                                '                                <img src="/static/images/down2.png" >\n' +
                                '                                <span>下载</span>\n' +
                                '                            </a>\n' +
                                '                            <div class="lay">\n' +
                                '                                <img src="/static/images/down3.png" >\n' +
                                '                                <span><a href="'+v.filename+'" target="_blank">在线查看</a></span>\n' +
                                '                            </div>\n' +
                                '                        </div>\n' +
                                '                    </div>\n' +
                                '                </div>'
                            $(".down-list").append(html);
                            download_page_index ++
                        })
                    }
                }else{
                    alert(res.msg)
                }
            },
            timeout: 2000,
            error: function(jqXHR,textStatus){
                console.log("请求失败，请稍后重试!");
            }
        })
    })

    var question_page_index = 2
    $(".load-more-question").on("click",function (){
        $.ajax({
            type: 'POST',
            url: question_url,
            data: {"page_index":question_page_index,"page_size":2},
            success: function(res){
                if(res.code == 0){
                    if(res.data.list.length == 0){
                        alert('已经没有数据了')
                    }else{
                        $.each(res.data.list,function (k,v){
                            var html = ' <div class="item ">\n' +
                                '                    <div class="top">\n' +
                                '                        <div class="cricle1">Q</div>\n' +
                                '                        <div class="tit">\n' + v.question +
                                '                        </div>\n' +
                                '                    </div>\n' +
                                '                    <div class="pos">\n' +
                                '                        <div class="ibox">\n' +
                                '                            <div class="cricle2">A</div>\n' +
                                '                            <div class="txt">\n' + v.answer +
                                '                            </div>\n' +
                                '                        </div>\n' +
                                '                    </div>\n' +
                                '                    <div class="more">\n' +
                                '                        <span >查看更多</span>\n' +
                                '                        <img src="/static/images/arrow3.png" >\n' +
                                '                    </div>\n' +
                                '                </div>'
                            $(".faq-list").append(html);
                            question_page_index ++
                        })
                    }
                }else{
                    alert(res.msg)
                }
            },
            timeout: 2000,
            error: function(jqXHR,textStatus){
                console.log("请求失败，请稍后重试!");
            }
        })
    })
})